package com.example.springbootbabyu.controller;

import com.example.springbootbabyu.assistant.Agent;
import com.example.springbootbabyu.entity.ChatForm;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

/**
 * 功能
 * 作者：梦天
 * 日期：2025/4/23 13:55
 */
@RestController
@RequestMapping("/chat")
@CrossOrigin
@Slf4j
public class ChatAiController {
    @Autowired
    private Agent agent;
    @PostMapping(value = "/stream", produces = "text/stream;charset=utf-8")
    public Flux<String> chatAi(@RequestBody ChatForm chatForm) {
        Flux<String> response = agent.chat(chatForm.getMemoryId(), chatForm.getMessage());
        log.info("response: {}", response);
        return response;
    }
}
